<template>
	<view class="permission-container">
		<view class="permission-dialog">
			<view class="permission-title">隐私权限申请</view>
			<view class="permission-content">
				<text class="permission-text">为了提供更好的服务，我们需要获取以下权限：</text>
				<view class="permission-item">
					<text class="permission-item-title">设备信息（OAID）</text>
					<text class="permission-item-desc">用于安全校验与服务优化</text>
				</view>
			</view>
			<view class="permission-links">
				<text class="link" @click="goToPrivacy">《隐私协议》</text>
				<text class="link" @click="goToUserAgreement">《用户协议》</text>
			</view>
			<view class="permission-buttons">
				<button class="btn-reject" @click="rejectPermission">不同意并退出</button>
				<button class="btn-agree" @click="agreePermission">同意</button>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {};
	},
	onLoad() {
		console.log("permission.vue加载");
		// 检查是否已经同意权限
		const permissionAgreed = uni.getStorageSync('permissionAgreed');
		if (permissionAgreed === 'true') {
			// 已同意，返回上一页
			setTimeout(() => {
				uni.switchTab({
					url: '/pages/home/home'
				});
			}, 100);
		}
	},
	// 拦截返回按钮事件
	onBackPress() {
		// 阻止返回，退出应用
		this.rejectPermission();
		return true; // 返回true表示阻止默认返回行为
	},
	methods: {
		goToPrivacy() {
			uni.navigateTo({
				url: '/pages/yinsi/yinsi'
			});
		},
		goToUserAgreement() {
			uni.navigateTo({
				url: '/pages/yonghu/yonghu'
			});
		},
		agreePermission() {
			// 设置已同意权限标志
			uni.setStorageSync('permissionAgreed', 'true');
			// 跳转到首页
			uni.switchTab({
				url: '/pages/home/home'
			});
		},
		rejectPermission() {
			// 用户拒绝，退出应用
			// #ifdef APP-PLUS
			plus.runtime.quit();
			// #endif
			// #ifdef MP
			uni.exitMiniProgram();
			// #endif
		}
	}
};
</script>

<style>
.permission-container {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.5);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 9999;
}

.permission-dialog {
	width: 80%;
	background-color: #fff;
	border-radius: 12rpx;
	padding: 40rpx;
	box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
}

.permission-title {
	font-size: 36rpx;
	font-weight: bold;
	text-align: center;
	margin-bottom: 30rpx;
}

.permission-content {
	margin-bottom: 30rpx;
}

.permission-text {
	font-size: 28rpx;
	color: #333;
	line-height: 1.6;
	display: block;
	margin-bottom: 20rpx;
}

.permission-item {
	background-color: #f8f8f8;
	padding: 20rpx;
	border-radius: 8rpx;
	margin-top: 20rpx;
}

.permission-item-title {
	font-size: 28rpx;
	font-weight: bold;
	color: #333;
	display: block;
	margin-bottom: 10rpx;
}

.permission-item-desc {
	font-size: 24rpx;
	color: #666;
}

.permission-links {
	display: flex;
	justify-content: center;
	margin-bottom: 30rpx;
}

.link {
	color: var(--Color);
	font-size: 24rpx;
	margin: 0 10rpx;
	text-decoration: underline;
}

.permission-buttons {
	display: flex;
	justify-content: space-between;
}

.btn-reject {
	flex: 1;
	height: 80rpx;
	line-height: 80rpx;
	background-color: #f5f5f5;
	color: #666;
	font-size: 28rpx;
	border-radius: 40rpx;
	margin-right: 20rpx;
}

.btn-agree {
	flex: 1;
	height: 80rpx;
	line-height: 80rpx;
	background-color: var(--Color);
	color: #fff;
	font-size: 28rpx;
	border-radius: 40rpx;
}
</style> 